<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>

   <head> 
      <title>Fletag Team Comparisons</title>
      <meta http-equiv="generator" content="PHP Designer 2006 - BETA" />
      <script src="sorttable.js"></script>
      <link href="default.css" rel="stylesheet" type="text/css" media="screen" />
   </head>

   <body>
         <div id="header">
	            <div id="logo">
		          <h1>FLeTaG</h1>
              </div>
         <div id="menu">
		     <ul>
             <li class="current_page_item"><a href="/fletag/compare.php">Team Comparisons</a></li>
			       <li><a href="/fletag/scoreboard.php">Scoreboard</a></li>
			       <li class="last"><a href="#">About</a></li>
       </ul>
	     </div>
      </div>

			<?php
			//Establish the db connection
			require('dbconn.inc.php');
			//Include the function library
			include('functions.inc.php');
			?>

	
		 
   <div id="content">
        <div class="post">
             <div class="title">
                  <h2><a href="#">Comparisons</a></h2>
             </div>
        </div>
   </div>
   <?php
		
		$players_sql = "Select player FROM players ORDER BY player ASC";
		$players_result = doQuery($players_sql);
		
        $match_sql = "SELECT team1,team2,matchtype
                     FROM games";
                     
        $match_result = doQuery($match_sql);
        
		while ($player_row = mysql_fetch_array($players_result))
		{
			$played_with = array();
			$played_against = array();
			$played = array();
			
			$player = $player_row['player'];
			
			while ($match_row = mysql_fetch_array($match_result))
			{
					$game_team1 = $match_row['team1'];
					$game_team2 = $match_row['team2'];
					$matchtype = $match_row['matchtype'];
					
					$team1 = explode (",",$game_team1);
					$team2 = explode (",",$game_team2);
					
					if (array_search ($player,$team1) !==FALSE)
					{
						foreach ($team1 as $player1)
						{
							if (isset($played_with[$player1]))
							{
								
								$played_with[$player1]++;
							}
							else
							{
								$played_with[$player1]=1;
							}
						}
						
						foreach ($team2 as $player2)
						{
							if (isset($played_against[$player2]))
							{
								$played_against[$player2]++;
							}
							else
							{
								$played_against[$player2]=1;
							}
						}
					}
					elseif (array_search ($player,$team2) !==FALSE)
					{
						foreach ($team2 as $player2)
						{
							if (isset($played_with[$player2]))
							{
								$played_with[$player2]++;
							}
							else
							{
								$played_with[$player2]=1;
							}
						}
						
						foreach ($team1 as $player1)
						{
							if (isset($played_against[$player1]))
							{
								$played_against[$player1]++;
							}
							else
							{
								$played_against[$player1]=1;
							}
						}
						
					}
              



			}
			mysql_data_seek($match_result,0);
			arsort($played_with);
			arsort($played_against);
			print ("<h3>$player - same team</h3>");
			print("<table BORDER cellpadding=5>");
			print ("<tr>");
			foreach ($played_with as $key => $value)
			{
				if ($player != $key)
				{
					print ("<th>$key</th>");
				}
			}
			print ("</tr>");
			print ("<tr>");
			foreach ($played_with as $key => $value)
			{
				if ($player != $key)
				{
					print ("<th>$value</th>");
				}
			}
			print ("</tr>");
			
			
			
			
			print ("</tr></table><br>");
			
			print ("<h3>$player - opposing team</h3>");
			print("<table BORDER cellpadding=5>");
			print ("<tr>");
			foreach ($played_against as $key => $value)
			{
				print ("<th>$key</th>");
			}
			print ("</tr>");
			foreach ($played_against as $key => $value)
			{
				print ("<th>$value</th>");
			}
			print ("</tr>");
			print ("</tr></table><br><br>");
		}
   
   ?>



   </div>
   </body>
</html>
